<template>
	<view class="container">
		<view v-for="(node, index) in nodeList" :key='index'>
			<!-- 轮播图 -->
			<jc-swiper v-if="node.componentModel.name=='banner'" :nodeModel='node' @itemHandle='itemHandle'></jc-swiper>
			<!-- 图文九宫格 -->
			<jc-grid v-if="node.componentModel.name=='grid'" :nodeModel='node' @itemHandle='itemHandle'></jc-grid>
			<!-- 通知栏 -->
			<jc-noticebar v-if="node.componentModel.name=='noticebar'" :nodeModel='node' @itemHandle='itemHandle' :noticeText='noticeText'></jc-noticebar>
			<!-- 自定义区域 -->
			<view v-if="node.componentModel.name=='custom'">
				<!-- <view style="display: flex;flex-direction: row;flex-wrap: wrap;align-content: flex-start;">
					<view style="display: flex;flex-direction: column;margin-top: 30rpx;width: 126rpx;margin-left: 20rpx;align-items: center;" @click="tagHandle(item)" v-for="(item, index1) in tagList" :key='index1'>
						<u--image :src='item.coverUrl' width='80rpx' height='80rpx'></u--image>
						<text style="font-size: 26rpx;margin-top: 12rpx;">{{item.name}}</text>
					</view>
				</view>
				<view style="display: flex;flex-direction: row;align-items: center;height: 100rpx;margin-left: 20rpx;margin-top: 20rpx;">
					<u-tabs :list="titleList" :scrollable="false" :current="current" @click="tabClick" lineColor="#5511ec" :activeStyle="{fontWeight: 'bold'}"></u-tabs>
				</view>
				<view style="width: 750rpx;display: flex;flex-direction: row;flex-wrap: wrap;align-content: flex-start;" class="content">
					<view v-for="(item, index) in guestList" :key='index' @click="guestHandle(item)"
					style="display: flex;flex-direction: column;margin-top: 20rpx;background-color: #FFF;width: 345rpx;margin-left: 20rpx;">
						<image :src="item.avatarUrl" mode='aspectFill' style="width: 100%;height: 400rpx;"></image>
						<view style="padding: 16rpx;">
							<view style="font-size: 28rpx;" class="limitLineNumOfTwo">{{item.nickname}}</view>
							<view style="margin-top: 10rpx;color: #fa3534;">¥{{item.sellingPrice}}/小时</view>
						</view>
					</view>
				</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	import { common } from '@/api/common.js'
	import {
		page
	} from '@/api/page.js'
	import {
		update
	} from '@/common/utils/update.js'
	export default {
		components: {},
		data() {
			return {
				pageConfig: {},
				nodeList: [],
				tagList: [],
				guestList: [],
				page: 1,
				size: 20,
				showEmpty: false,
				isLastPage: false,
				titleList: [{name: '女生'}, {name: '男生'}],
				current: 0,
				noticeText: ''
			}
		},
		onLoad(options) {
			/**********************小程序普通二维码接收参数******************/
			if (options.q) {
				console.log('小程序普通二维码接收的参数', decodeURIComponent(options.q))
				getApp().globalData.sceneConfig = this.$tools.urlParmasToObj(decodeURIComponent(options.q))
			}else if(options){
				getApp().globalData.sceneConfig = options
			}
			if (getApp().globalData.sceneConfig) {
				this.setSceneConfig(getApp().globalData.sceneConfig)
			}
			var _this = this
			uni.$on('checkUpdate', function(data) {
				if(data.scene == 'mine'){
					_this.getAssetVersion(data.scene)
				}
			})
			this.getAssetVersion('home')
			this.getPageByClientname()
			
		}, 
		onShow() {
			console.log('首页onshow')
		},
		onUnload() {
			uni.$off('checkUpdate')
		},
		onPullDownRefresh() {
			this.getPageByClientname()
		},
		methods: {
			setSceneConfig(sceneConfig) {
				console.log('sceneConfig', sceneConfig)
				switch (sceneConfig.CHN) {
					case 'regCode':
						uni.navigateTo({
							url: '/pages/login/reg?parentCode=' + sceneConfig.parentCode
						})
						break;
					case 'public':
						this.$store.commit('lessee', sceneConfig.lessee)
						break;
					default:
						break;
				}
			},
			getPageByClientname() {
				page.getPageByClientname({
					name: this.$Route.name
				}).then(res => {
					uni.stopPullDownRefresh()
					if (res.data.code == 10000) {
						this.pageConfig = res.data.data
						uni.setNavigationBarTitle({
							title: this.pageConfig.title
						})
						// 加载节点
						this.nodeList = res.data.data.nodeList
						for(var node of this.nodeList){
							if(node.componentModel.name == 'itemList'){
								this.itemListType = node.componentModel.name
								this.itemListNode = node
								this.page = 1
								// this.getPageList()
							}else if(node.componentModel.name == 'itemGrid'){
								this.itemListType = node.componentModel.name
								this.itemListNode = node
								var itemList = []
								for(var advert of node.advertList){
									itemList.push(advert.itemModel)
								}
								this.itemListNode.itemList = itemList
							}else if(node.componentModel.name == 'noticebar'){
								if(node.options1 == 'dynamic'){
									this.getHomeNoticeText(node.query, node)
								}
							}
						}
					}
				})
			},
			getAssetVersion(scene){
				common.findClientInfo().then(res => {
					if (res.data.code == 10000) {
						var clientInfo = res.data.data
						this.$storage.setStorageDataSync('clientInfo', res.data.data)
						// #ifdef APP-PLUS
						if (uni.getSystemInfoSync().model != 'iPhoneSimulator') {
							console.log('当前平台', uni.getSystemInfoSync())
							update.checkAppUpdate(res.data.data, scene)
						}
						// #endif
					}
				})
			},
			itemHandle(item) {
				var link = ''
				if(item.link){
					link = JSON.parse(item.link)
				}
				var query = ''
				if(item.query){
					query = JSON.parse(item.query)
				}
				switch (link.modal) {
					case 'push':
						this.$Router.push({
							name: link.name,
							params: query
						})
						break;
					case 'pushTab':
						this.$Router.pushTab({
							name: link.name,
							params: query
						})
						break;
					default:
						break;
				}
			},
			getHomeNoticeText(url, node) {
				common.operateActionPost(url, {}).then(res => {
					if (res.data.code == 10000) {
						var textList = res.data.data.textList
						if(node.direction == 'row'){
							this.noticeText = textList[0]
						}else if(node.direction == 'column'){
							this.noticeText = textList
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container{
		padding-bottom: 40rpx;
	}
	.itemList{
		width: 710rpx;
		margin-left: 20rpx;
		margin-top: 20rpx;
		border-radius: 16rpx;
		display: flex;
		flex-direction: column;
		background-color: #FFF;
		padding-top: 30rpx;
		padding-bottom: 10rpx;
		.item{
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 177.5rpx;
			.image{
				width: 100rpx;
				height: 100rpx;
			}
			.text{
				margin-top: 10rpx;
				margin-bottom: 20rpx;
				font-size: 28rpx;
			}
		}
	}
	
</style>
